import { createHashRouter, redirect } from 'react-router'
import Home from '@/view/home';
import AboutDetail from '@/view/about/children/about-detail';
const authChech = async() => {
  if(Math.random() > 0.5) {
    return true
  }
}
export const router = createHashRouter([
    {
      path: '/',
      Component: Home,
      loader: () => ({title: '首页'})
    },
    {
      path: '/about',
      loader: () => ({title: '详情页'}),
      lazy: async (params) => {
        const component = await import('@/view/about')
        return { Component: component.default }
      }, 
      children: [
        {
          path: 'detail',
          Component: AboutDetail,
          loader: async () => {
            const isLogin = await authChech()
            console.log(isLogin)
            if(!isLogin) {
              return redirect('/')
            }
            return { title: '首页' }
          }
        }
      ]
    },
  ]);